package com.monster.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.monster.mapper.UserDetailMapper;
import com.monster.pojo.Permission;
import com.monster.pojo.User;
import com.monster.service.UserDetailService;
import com.monster.vo.RoleVO;
import com.monster.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class UserDetailServiceImpl extends ServiceImpl<UserDetailMapper, User> implements UserDetailService {
    @Override
    public UserVO findUserDetailsByUsername(String username) {
        //根据name查询User表
        UserVO userVO = baseMapper.findUserByName(username);
        //根据uservoid查询角色
        List<RoleVO> roles = baseMapper.findRolesByUserId(userVO.getId());
        for (RoleVO role : roles) {
            //根据rolesid查询权限
            List<Permission> permissionSet = baseMapper.findPermissionByRoleId(role.getId());
            role.setPermissionSet(permissionSet);

        }
        userVO.setRoles(roles);
        return userVO;
    }
}
